﻿package code {
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.utils.getTimer;
	import flash.globalization.LastOperationStatus;

	public class CircleLineCollision extends Sprite {
		var circle:Ball;
		var lines:Array;
		var previousTime:Number;
		var collisionObjects:Array;
		
		public function CircleLineCollision() {
			previousTime = 0;
			lines = new Array();
			collisionObjects = new Array();
			init();
		}
		
		public function init(){
			createBall();
			createTestLines();
			addEventListener(Event.ENTER_FRAME, update);
			addEventListener(MouseEvent.MOUSE_UP, mouseIsUp);
		}
		
		public function createBall(){
			circle = new Ball("Polygon", 15, 20, 0x00FF00, 3, false);
			circle.x = 100;
			circle.y = 100;
			circle.createLinesArray();
			addChild(circle);
							 
		}
		
		public function createTestLines(){
			/*var line:GameObject = new GameObject("Rectangle", 100, 4, 0x000000, 1, true, 0, 50);
			line.x = 75;
			line.y = 300;
			line.createLinesArray();
			for each(var l:Line in line.shape.linesArray){
				//trace(l.a.x, l.a.y, l.b.x, l.b.y);
			}
			collisionObjects.push(line);
			addChild(line);
			*/
			
			var realLine:Line = new Line(new Vertex(75,300), new Vertex(175,300), 1, 0x000000);
			collisionObjects.push(realLine);
			addChild(realLine);
		}
		
		public function update(e:Event){
			var currentTime = getTimer();
			var dT = currentTime - previousTime;
			circle.update(collisionObjects, dT);
			previousTime = currentTime;
			
		}
		
		public function mouseIsUp(e:MouseEvent){
			
		}
	}
	
}
